<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<%@ page import="java.util.*" %>
<%@ page import="com.hilaver.dzmis.Constants" %>
<%@ page import="com.hilaver.dzmis.util.*" %>
<%@ page import="com.hilaver.dzmis.service.impl.*" %>
<%@ page import="com.hilaver.dzmis.product.*" %>
<%@ page import="com.hilaver.dzmis.codetable.*" %>
<%
	Integer id = Integer.parseInt(request.getParameter("id"));

	ProductIdentificationServiceImpl piService = new ProductIdentificationServiceImpl();
	CtServiceImpl ctService = new CtServiceImpl();
	I18nServiceImpl i18n = new I18nServiceImpl();
	Locale locale = (Locale) request.getSession().getAttribute(
			Constants.SESSION_LOCALE);
	
	ProductIdentification pi = piService.getObj(id);
	List<ProductYarn> pyList = piService.getDiffYarn(pi);
	int maxColorCount = piService.getMaxColorCountInOrder(pi);
	Set<ProductOrderItem> poiSets = pi.getProductOrderItems();
	List<Float> percentageList = piService.getColorPercentage(pi);
	BiMeasureSpecification biMS = pi.getBiMeasureSpecification();
	Set<ProductMeasureSpecificationItem> pMsiSet = pi.getProductMeasureSpecificationItems();
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="com.hilaver.dzmis.basicinfo.BiMeasureSpecification"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0"><meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> 
<link rel="stylesheet" type="text/css" href="../../styles/dzbase.css" media="all"/>
<title><%=pi.getReference() %>--<%=pi.getPatronageNumer() %>--Version: <%=ctService.getDescription(CtVersion.class.getName(), pi.getCtVersion(), locale) %></title>
</head>
<body>
	<div id="productIdentification" style="width: 170mm;margin-top: 10px;">
		<table cellspacing="0" id="the-table" style="width: 95%;">
			<tr>
				<td style="background:#eeeeee; text-align: center;">
					<%=i18n.getShortMessage(locale, "ui.productidentification.style") %>
				</td>
				<td colspan="3">
					<%=pi.getStyle() %>
				</td>
			</tr>
			<tr>
				<td style="background:#eeeeee; text-align: center; width: 20%;">
					<%=i18n.getShortMessage(locale, "message.edit.customername") %>
				</td>
				<td>
					<%=pi.getBiFranceCustomer().getName() %>
					<%=pi.getBiFranceCustomer().getDepartment() == null?"": "--" + pi.getBiFranceCustomer().getDepartment() %>
				</td>
				<td style="background:#eeeeee; text-align: center; width: 20%;">
					<%=i18n.getShortMessage(locale, "ui.productidentification.seasonnumber") %>
				</td>
				<td>
					<%=ctService.getDescription(CtSeasonNumber.class.getName(), pi.getCtSeasonNumber(), locale) %>
				</td>
			</tr>
			<tr>
				<td style="background:#eeeeee; text-align: center; width: 20%;">
					<%=i18n.getShortMessage(locale, "message.edit.linkman") %>
				</td>
				<td>
					<%=pi.getCustomerLinkman() %>
				</td>
				<td style="background:#eeeeee; text-align: center; width: 20%;">
					<%=i18n.getShortMessage(locale, "ui.reference.reference") %>
				</td>
				<td>
					<%=pi.getReference() %>
				</td>
			</tr>
			<tr>
				<td style="background:#eeeeee; text-align: center; width: 20%;">
					<%=i18n.getShortMessage(locale, "ui.productidentification.model") %>
				</td>
				<td>
					<%=pi.getModel() %>
				</td>
				<td style="background:#eeeeee; text-align: center; width: 20%;">
					<%=i18n.getShortMessage(locale, "message.edit.createdate") %>(d/m/Y)
				</td>
				<td>
					<%=StringUtils.toString(pi.getCreateDate()) %>
				</td>
			</tr>
			<tr>
				<td style="background:#eeeeee; text-align: center; width: 20%;">
					<%=i18n.getShortMessage(locale, "ui.productidentification.chartversion") %>
				</td>
				<td>
					<%=ctService.getDescription(CtVersion.class.getName(), pi.getCtVersion(), locale) %>
				</td>
				<td style="background:#eeeeee; text-align: center; width: 20%;">
					<%=i18n.getShortMessage(locale, "ui.productidentification.patronagenumer") %>
				</td>
				<td>
					<%=pi.getPatronageNumer() %>
				</td>
			</tr>
		</table>
		<table cellspacing="0" id="the-table" style="width: 95%;margin-top: 5px;">
			<tr>
				<td rowspan="4" style="background:#eeeeee; text-align: center;width: 20%;">
					<%=i18n.getShortMessage(locale, "ui.productidentification.set2") %>
				</td>
				<td style="background:#eeeeee; text-align: center;">
					<%=i18n.getShortMessage(locale, "ui.reference.front") %>
				</td>
				<td style="background:#eeeeee; text-align: center;">
					<%=i18n.getShortMessage(locale, "ui.reference.back") %>
				</td>
				<td style="background:#eeeeee; text-align: center;">
					<%=i18n.getShortMessage(locale, "ui.reference.sleeves") %>
				</td>
			</tr>
			<tr>
				<td>
					<%=pi.getFront() %>
				</td>
				<td>
					<%=pi.getBack() %>
				</td>
				<td>
					<%=pi.getSleeves() %>
				</td>
			</tr>
			<tr>
				<td style="background:#eeeeee; text-align: center;">
					<%=i18n.getShortMessage(locale, "ui.reference.bottomthrum") %>
				</td>
				<td style="background:#eeeeee; text-align: center;">
					<%=i18n.getShortMessage(locale, "ui.reference.sleevesthrum") %>
				</td>
				<td style="background:#eeeeee; text-align: center;">
					<%=i18n.getShortMessage(locale, "ui.reference.necklinethrum") %>
				</td>
			</tr>
			<tr>
				<td>
					<%=pi.getBottomThrum() %>
				</td>
				<td>
					<%=pi.getSleevesThrum() %>
				</td>
				<td>
					<%=pi.getNecklineThrum() %>
				</td>
			</tr>
		</table>
		<table cellspacing="0" id="the-table" style="width: 95%;margin-top: 5px;">
			<tr>
				<td style="background:#eeeeee; text-align: center;">
					<%=i18n.getShortMessage(locale, "ui.reference.needle") %>
				</td>
				<td>
					<%=pi.getNeedle() %>
				</td>
				<td style="background:#eeeeee; text-align: center;">
					<%=i18n.getShortMessage(locale, "ui.reference.machinetype") %>
				</td>
				<td>
					<%=ctService.getDescription(CtMachineType.class.getName(), pi.getCtMachineType(),locale) %>
				</td>
				<td style="background:#eeeeee; text-align: center;">
					<%=i18n.getShortMessage(locale, "ui.reference.weight") %>
				</td>
				<td>
					<%=pi.getWeight() %>
				</td>
				<td style="background:#eeeeee; text-align: center;">
					<%=i18n.getShortMessage(locale, "ui.productidentification.precentage") %>(%)
				</td>
			</tr>
			<% int i = 1; 
			for(ProductYarn py : pyList){ %>
			<tr>
				<td style="background:#eeeeee; text-align: center;">
					<%=i18n.getShortMessage(locale, "ui.productidentification.fil") %>&nbsp;&nbsp;<%=i %>
				</td>
				<td>
					<%=py.getFil() %>
				</td>
				<td style="background:#eeeeee; text-align: center;">
					<%=i18n.getShortMessage(locale, "message.edit.materialtype") %>
				</td>
				<td colspan="3">
					<%=ctService.getDescription(CtMaterialType.class.getName(), py.getBiYarn().getCtMaterialType(), locale) %>
				</td>
				<td>
					<%=py.getPrecentage() %>
				</td>
			</tr>
			<%i++;} %>
		</table>
		<table cellspacing="0" id="the-table" style="width: 95%;margin-top: 5px;">
			<tr>
				<td align="center">
					&nbsp;&nbsp;&nbsp;&nbsp;<img width="400" src="../../_temp/<%=pi.getChartName() %>"/>
				</td>
			</tr>
		</table>
		<table cellspacing="0" id="the-table" style="width: 95%;margin-top: 5px;">
			<tr>
				<td>
					&nbsp;&nbsp;&nbsp;&nbsp;<%=pi.getComment() %>
				</td>
			</tr>
		</table>
		
		<table cellspacing="0" id="the-table" style="width: 95%;margin-top: 5px;">
			<tr>
				<td rowspan="2">
					<%=i18n.getShortMessage(locale, "ui.order.color") %>
				</td>
				<%for(short j = 0; j < maxColorCount; j ++){ %>
				<td>
					Col.&nbsp;<%=(char)('A' + j) %>
				</td>
				<%} %>
				<td colspan="6">
					<%=i18n.getShortMessage(locale, "ui.productidentification.ordernumber") %>:&nbsp;&nbsp;<%=pi.getOrderNumber() %>
				</td>
				<td rowspan="2" style="background:#eeeeee;">
					<%=i18n.getShortMessage(locale, "message.list.total") %>
				</td>
			</tr>
			<tr>
				<%for(short j = 0; j < percentageList.size(); j ++){ %>
				<td>
					<%=percentageList.get(j) %>%
				</td>
				<%} %>
				<td>
					S
				</td>
				<td>
					M
				</td>
				<td>
					L
				</td>
				<td>
					XL
				</td>
				<td>
					XXL
				</td>
				<td>
					XXXL
				</td>
			</tr>
			<%
			int sTotal = 0;
		    int mTotal = 0;
		    int lTotal = 0;
		    int xlTotal = 0;
		    int xxlTotal = 0;
		    int xxxlTotal = 0;
		    int total = 0;
			for(ProductOrderItem poi : poiSets){
				Set<ProductOrderItemColor> poicSets = poi.getProductOrderItemColors();
			%>
				<tr>
					<td>
						<%=poi.getColorNumber() %>
					</td>
					<%for(ProductOrderItemColor poic : poicSets){ %>
						<td>
							<%=poic.getColorNumber() %>
						</td>
					<%} %>
					<td style="text-align: right;">
						<%
							sTotal += poi.getAmountS();
							out.print(poi.getAmountS()); 
						%>
					</td>
					<td style="text-align: right;">
						<%
							mTotal += poi.getAmountM();
							out.print(poi.getAmountM()); 
						%>
					</td>
					<td style="text-align: right;">
						<%
							lTotal += poi.getAmountL();
							out.print(poi.getAmountL()); 
						%>
					</td>
					<td style="text-align: right;">
						<%
							xlTotal += poi.getAmountXl();
							out.print(poi.getAmountXl()); 
						%>
					</td>
					<td style="text-align: right;">
						<%
							xxlTotal += poi.getAmountXxl();
							out.print(poi.getAmountXxl()); 
						%>
					</td>
					<td style="text-align: right;">
						<%
							xxxlTotal += poi.getAmountXxxl();
							out.print(poi.getAmountXxxl()); 
						%>
					</td>
					<td style="background:#eeeeee;text-align: right;">
						<%
						total += poi.getTotal();
							out.print(poi.getTotal()); 
						%>
					</td>
				</tr>
			<%} %>
			<tr>
				<td colspan="3" style="background:#eeeeee; text-align: right;">
					<%=i18n.getShortMessage(locale, "message.list.total") %>
				</td>
				<td style="background:#eeeeee; text-align: right;">
					<%=sTotal %>
				</td>
				<td style="background:#eeeeee; text-align: right;">
					<%=mTotal %>
				</td>
				<td style="background:#eeeeee; text-align: right;">
					<%=lTotal %>
				</td>
				<td style="background:#eeeeee; text-align: right;">
					<%=xlTotal %>
				</td>
				<td style="background:#eeeeee; text-align: right;">
					<%=xxlTotal %>
				</td>
				<td style="background:#eeeeee; text-align: right;">
					<%=xxxlTotal %>
				</td>
				<td style="background:#eeeeee; text-align: right;">
					<%=total %>
				</td>
			</tr>
		</table>
		
		<table cellspacing="0" id="the-table" style="width: 95%;margin-top: 5px; page-break-before:always;page-break-after: always;">
			<tr>
				<td align="center">
					&nbsp;&nbsp;&nbsp;&nbsp;<img width="400" src="../../_temp/<%=pi.getPhotoName() %>"/>
				</td>
			</tr>
		</table>
		
		<table cellspacing="0" id="the-table" style="width: 95%;margin-top: 5px;">
			<tr>
				<td colspan="8" style="text-align: center;border-right-style: dashed;">
					BAREME DE TAILLES
				</td>
				<td colspan="5" style="text-align: center;">
					Taille de base
				</td>
				<td>
					L
				</td>
			</tr>
			<tr>
				<td style="text-align: center;" rowspan="2">
					N°
				</td>
				<td style="text-align: center;" rowspan="2">
					DESIGNATIONS
				</td>
				<td colspan="6" style="text-align: center;border-right-style: dashed;">
					TAILLES
				</td>
				<td colspan="6" style="text-align: center;">
					Mesures Répétition
				</td>
			</tr>
			<tr>
				<td style="text-align: center;">
					S
				</td>
				<td style="text-align: center;">
					M
				</td>
				<td style="text-align: center;">
					L
				</td>
				<td style="text-align: center;">
					XL
				</td>
				<td style="text-align: center;">
					XXL
				</td>
				<td style="text-align: center;border-right-style: dashed;">
					XXXL
				</td>
				<td style="text-align: center;">
					S
				</td>
				<td style="text-align: center;">
					M
				</td>
				<td style="text-align: center;">
					L
				</td>
				<td style="text-align: center;">
					XL
				</td>
				<td style="text-align: center;">
					XXL
				</td>
				<td style="text-align: center;">
					Tol
				</td>
			</tr>
			<%for(ProductMeasureSpecificationItem  pmsi : pMsiSet){%>
			<tr>
				<td style="text-align: center;">
					<%=pmsi.getNumber() %>
				</td>
				<td style="text-align: center;">
					<%=pmsi.getDesignations()==null?"":pmsi.getDesignations() %>
				</td>
				<td style="text-align: center;">
					<%=pmsi.getSizeS()==null?"":pmsi.getSizeS() %>
				</td>
				<td style="text-align: center;">
					<%=pmsi.getSizeM()==null?"":pmsi.getSizeM() %>
				</td>
				<td style="text-align: center;">
					<%=pmsi.getSizeL()==null?"":pmsi.getSizeL() %>
				</td>
				<td style="text-align: center;">
					<%=pmsi.getSizeXl()==null?"":pmsi.getSizeXl() %>
				</td>
				<td style="text-align: center;">
					<%=pmsi.getSizeXxl()==null?"":pmsi.getSizeXxl() %>
				</td>
				<td style="text-align: center;border-right-style: dashed;">
					<%=pmsi.getSizeXxxl()==null?"":pmsi.getSizeXxxl() %>
				</td>
				<td style="text-align: center;">
					<%=pmsi.getRepeatS()==null?"":pmsi.getRepeatS() %>
				</td>
				<td style="text-align: center;">
					<%=pmsi.getRepeatM()==null?"":pmsi.getRepeatM() %>
				</td>
				<td style="text-align: center;">
					<%=pmsi.getRepeatL()==null?"":pmsi.getRepeatL() %>
				</td>
				<td style="text-align: center;">
					<%=pmsi.getRepeatXl()==null?"":pmsi.getRepeatXl() %>
				</td>
				<td style="text-align: center;">
					<%=pmsi.getRepeatXxl()==null?"":pmsi.getRepeatXxl() %>
				</td>
				<td style="text-align: center;">
					+/-<%=pmsi.getTolerance()==null?"":pmsi.getTolerance() %>
				</td>
			</tr>
			<%} %>
		</table>
    </div>
</body>
</html>